package cn.rui.aop;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局的处理异常的类  aop思想
 * @author 徽州大都督
 * @date 2020/8/14
 */
@ControllerAdvice(basePackages = "cn.rui.controller")
public class ExceptionHandler {

    //当发生异常时处理方式
    @org.springframework.web.bind.annotation.ExceptionHandler(RuntimeException.class) //运行时异常
    @ResponseBody
    public Map handlers(){
        Map map = new HashMap ();
        map.put ("code","1");
        map.put ("msg","系统错误");

        return map;
    }
}
